package www.controller.imgbbs;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;

import www.imgbbs.ImgbbsDTO;
import www.imgbbs.ImgbbsMgr;

public class ImgbbsReadController implements Controller {
	private ImgbbsMgr mgr;
	
	public void setMgr(ImgbbsMgr mgr) {
		this.mgr = mgr;
	}

	@Override
	public ModelAndView handleRequest(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		ModelAndView mv = new ModelAndView();
		int nowPage=0;
		int nowBlock=0;
		String searchColumn=null;
		String searchWord=null;
		if(request.getParameter("nowPage")!=null){
			nowPage = Integer.parseInt(request.getParameter("nowPage"));
		}
		
		if(request.getParameter("nowBlock")!=null){
			nowBlock = Integer.parseInt(request.getParameter("nowBlock"));
		}
		
		if(request.getParameter("searchColumn")!=null){
			searchColumn = request.getParameter("searchColumn");
		}
		
		if(request.getParameter("searchWord")!=null){
			searchWord = request.getParameter("searchWord");
		}
		Map map = new HashMap();
		map.put("nowPage", nowPage);
		map.put("nowBlock", nowBlock);
		map.put("searchColumn", searchColumn);
		map.put("searchWord", searchWord);
		
		ImgbbsDTO dto = new ImgbbsDTO();
		int num = Integer.parseInt(request.getParameter("num"));
		if(mgr.upCount(num)){
		dto = mgr.read(num);
		}
		mv.addAllObjects(map);
		mv.addObject("dto",dto);
		mv.setViewName("imgRead");
		return mv;
	}

}
